In-class Ex03

Author

Zhang Chenbin

Published

Invalid Date

Modified

September 9, 2024

Code
 pacman::p_load(sf, spNetwork, tmap, tidyverse)
Code
network <- st_read(dsn="data/geospatial", 
                   layer="Punggol_St")
Reading layer `Punggol_St' from data source 
  `D:\cbzhang2023\ISSS626-1\In-class_EX\In-class_EX03\data\geospatial' 
  using driver `ESRI Shapefile'
Simple feature collection with 2642 features and 2 fields
Geometry type: LINESTRING
Dimension:     XY
Bounding box:  xmin: 34038.56 ymin: 40941.11 xmax: 38882.85 ymax: 44801.27
Projected CRS: SVY21 / Singapore TM
Code
childcare <- st_read(dsn="data/geospatial",
                     layer="Punggol_CC") %>%
  st_zm(drop = TRUE,
        what = "ZM")
Reading layer `Punggol_CC' from data source 
  `D:\cbzhang2023\ISSS626-1\In-class_EX\In-class_EX03\data\geospatial' 
  using driver `ESRI Shapefile'
Simple feature collection with 61 features and 1 field
Geometry type: POINT
Dimension:     XYZ
Bounding box:  xmin: 34423.98 ymin: 41503.6 xmax: 37619.47 ymax: 44685.77
z_range:       zmin: 0 zmax: 0
Projected CRS: SVY21 / Singapore TM
Code
plot(st_geometry(network))
plot(childcare,add=T,col='red',pch = 19)

Code
plot(network)
plot(childcare,add=T,col='red',pch = 19)

Code
tmap_mode('view')
tmap mode set to interactive viewing
Code
tm_shape(childcare) + 
tm_dots(col = "darkgreen") +
tm_shape(network) +
tm_lines()
Code
tmap_mode('plot')
tmap mode set to plotting
Code
lixels <- lixelize_lines(network,
                       700,
                       mindist = 350)
Code
samples <- lines_center(lixels)

tmap_mode('view')
tmap mode set to interactive viewing
Code
tm_shape(lixels) +
  tm_lines() +
tm_shape(samples) +
  tm_dots(size = 0.01)
Code
tmap_mode('plot')
tmap mode set to plotting
Code
densities <- nkde(network, 
                  events = childcare,
                  w = rep(1, nrow(childcare)),
                  samples = samples,
                  kernel_name = "quartic",
                  bw = 300, 
                  div= "bw", 
                  method = "simple")
Code
kfun_childcare <- kfunctions(network, 
                             childcare,
                             start = 0, 
                             end = 1000, 
                             step = 50, 
                             width = 50, 
                             nsim = 50, 
                             resolution = 50,
                             verbose = FALSE, 
                             conf_int = 0.05)
Code
kfun_childcare$plotg